<?php


namespace App\Common;


trait GlobalCode
{
    public function code500(string $txt = "网络错误", array $data = []){
        $msg['code'] = 500;
        $msg['msg'] = $txt;
        $msg['data'] = $data;
        return response()->json($msg);
    }
    public function code200(string $txt = "提交成功",array $data = []){
        $msg['code'] = 200;
        $msg['msg'] = $txt;
        $msg['data'] = $data;
        return response()->json($msg);
    }
    public function code404(string $txt = "数据不存在",array $data = []){
        $msg['code'] = 404;
        $msg['msg'] = $txt;
        $msg['data'] = $data;
        return response()->json($msg);
    }

    public function code201(string $txt = "程序异常，请联系管理员",array $data = []){
        $msg['code'] = 201;
        $msg['msg'] = $txt;
        $msg['data'] = $data;
        return response()->json($msg);
    }
}
